package com.huige.config;

import com.huige.interceptor.MyInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @Author 朱志辉
 * @Create 2024/7/19 下午3:24
 * @Version 1.0
 * Description: mvc组件的配置类
 */
@Configuration
@ComponentScan({"com.huige.controller","com.huige.error"})
@EnableWebMvc//开启mvc
public class MvcConfig implements WebMvcConfigurer {

    //1.handlerMapping handlerAdapter json转化器
    //2.视图解析器，指定前后缀


    //开启静态资源查找
    //静态资源映射 dispatcherServlet-》 servletContext -> servlet -> servletRequest -> servletResponse
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //配置方案1：拦截全部请求
        //registry.addInterceptor(new MyInterceptor());

        //配置方案2：指定地址拦截
        registry.addInterceptor(new MyInterceptor()).addPathPatterns("/user/**");

        //配置方案3：指定地址不拦截
        registry.addInterceptor(new MyInterceptor()).excludePathPatterns("/user/data1");
    }
}
